#region Copyright (c) 2003 - 2006 Toenda Software Development
/*
 * Copyright (c) 2003 - 2006 Toenda Software Development
 */
#endregion

using System;

namespace Toenda.Rails {
	namespace System {
		/// <summary>
		/// Class Time
		/// </summary>
		public class TimeHandler {
			/// <summary>
			/// A self registered object
			/// </summary>
			public static TimeHandler Current = new TimeHandler();

			private DateTime m_oDateTime = new DateTime();
			private static long m_lTempLoadingTime;

			/// <summary>
			/// Default constructor
			/// </summary>
			public TimeHandler() {
				m_oDateTime = DateTime.Now;
			}

			/// <summary>
			/// Get current datetime
			/// </summary>
			public DateTime CurrentDateTime {
				get { return m_oDateTime; }
			}

			/// <summary>
			/// Get loading time
			/// </summary>
			public long TempLoadingTime {
				get { return m_lTempLoadingTime; }
			}

			/// <summary>
			/// Start the loading time ticker
			/// </summary>
			public void StartLoadingTime() {
				m_lTempLoadingTime = m_oDateTime.Ticks;
			}

			/// <summary>
			/// Stop the loading time picker and return the loading time.
			/// </summary>
			/// <param name="lStartLoading"></param>
			/// <returns></returns>
			public string GetLoadingTime(long lStartLoading) {
				long lLoadingTime;
				long lEndLoading;

				m_oDateTime = DateTime.Now;
				lEndLoading = m_oDateTime.Ticks;

				lLoadingTime = lEndLoading - lStartLoading;

				TimeSpan oTimeSpan = new TimeSpan(lLoadingTime);

				return "Page generated in "
					+ oTimeSpan.Seconds.ToString()
					+ "."
					+ oTimeSpan.Milliseconds.ToString()
					+ " seconds";
			}
		}
	}
}
